package com.sc.VenusQueryBeta.presenter.setting;

import com.sc.VenusQueryBeta.contract.setting.SettingContract;
import com.sc.VenusQueryBeta.model.setting.SettingModel;

import io.reactivex.functions.Consumer;

/**
 * Created by SC-02 on 2018/9/19.
 * 設置presenter 继承契约类的presenper
 */

public class SettingPresenter extends SettingContract.SettingPresenter{
    @Override
    protected SettingContract.ISettingModel getModel() {
        return   SettingModel.newInstance();
    }

    @Override
    public void onStart() {

    }
    /**
     * 实例化
     * @return 提供对象给外界
     */
    public static SettingPresenter newInstance() {
        return new SettingPresenter();
    }

    @Override
    public void exit(String loginUserId) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.exit(loginUserId).subscribe(new Consumer<String>() {
            @Override
            public void accept(String exitLoginBean) throws Exception {
                if (mIView != null)
                    mIView.exitLoginBean(exitLoginBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error"+throwable.getMessage());
                    mIView.showNetworkError();
                }
            }
        }));
    }
}
